import storage from '@/utils/storage'
import config from '@/config'
const colorStyle = ['#d20000', '#fb8701', '#febc1f', '#12D199', '#69c612', '#40c0fc', '#2590D3']
// 日常记录 收缩压判断
export function dynamicSsy(value) {
	if (!value) {
		return {}
	}
	const resultData = {}
	if (value >= 180) {
		resultData.style = 'color:' + colorStyle[0]
		resultData.color = colorStyle[0]
		resultData.info = '血压水平危险，应马上就医!'
		resultData.code = '1'
		resultData.name = '3级高血压'
	} else if (value >= 160) {
		resultData.style = 'color:' + colorStyle[1]
		resultData.color = colorStyle[1]
		resultData.info = '2级高压水平,需要规范治疗!'
		resultData.code = '2'
		resultData.name = '2级高血压'
	} else if (value >= 140) {
		resultData.style = 'color:' + colorStyle[2]
		resultData.color = colorStyle[2]
		resultData.info = '1级高压水平,加强运动可调节血压!'
		resultData.code = '3'
		resultData.name = '1级高血压'
	} else if (value >= 120) {
		resultData.style = 'color:' + colorStyle[3]
		resultData.color = colorStyle[3]
		resultData.info = '血压正常高值水平,要注意控制!'
		resultData.code = '4'
		resultData.name = '正常高值'
	} else if (value >= 90) {
		resultData.style = 'color:' + colorStyle[4]
		resultData.color = colorStyle[4]
		resultData.info = '血压正常,请注意保持!'
		resultData.code = '5'
		resultData.name = '正常血压'
	} else {
		resultData.style = 'color:' + colorStyle[5]
		resultData.color = colorStyle[5]
		resultData.info = '血压偏低，有不适请咨询医生!'
		resultData.code = '6'
		resultData.name = '低血压'
	}
	return resultData
}
// 日常记录 舒张压判断
export function dynamicSzy(value) {
	if (!value) {
		return {}
	}
	const resultData = {}
	if (value >= 110) {
		resultData.style = 'color:' + colorStyle[0]
		resultData.color = colorStyle[0]
		resultData.info = '血压水平危险，应马上就医!'
		resultData.code = '1'
		resultData.name = '3级高血压'
	} else if (value >= 100) {
		resultData.style = 'color:' + colorStyle[1]
		resultData.color = colorStyle[1]
		resultData.info = '2级高压水平,需要规范治疗!'
		resultData.code = '2'
		resultData.name = '2级高血压'
	} else if (value >= 90) {
		resultData.style = 'color:' + colorStyle[2]
		resultData.color = colorStyle[2]
		resultData.info = '1级高压水平,加强运动可调节血压!'
		resultData.code = '3'
		resultData.name = '1级高血压'
	} else if (value >= 80) {
		resultData.style = 'color:' + colorStyle[3]
		resultData.color = colorStyle[3]
		resultData.info = '血压正常高值水平,要注意控制!'
		resultData.code = '4'
		resultData.name = '正常高值'
	} else if (value >= 60) {
		resultData.style = 'color:' + colorStyle[4]
		resultData.color = colorStyle[4]
		resultData.info = '血压正常,请注意保持!'
		resultData.code = '5'
		resultData.name = '正常血压'
	} else {
		resultData.style = 'color:' + colorStyle[5]
		resultData.color = colorStyle[5]
		resultData.info = '血压偏低，有不适请咨询医生!'
		resultData.code = '6'
		resultData.name = '低血压'
	}
	return resultData
}

// 日常记录 收缩压舒张判断
export function dynamicSS(value, value2) {
	if (!value) {
		return {}
	}

	const resultData = {}
	if (value >= 180 || value2 >= 110) {
		resultData.style = 'color:' + colorStyle[0]
		resultData.color = colorStyle[0]
		resultData.info = '血压水平危险，应马上就医!'
		resultData.code = '1'
		resultData.name = '3级高血压'
	} else if (value >= 160 || value2 >= 100) {
		resultData.style = 'color:' + colorStyle[1]
		resultData.color = colorStyle[1]
		resultData.info = '2级高压水平,需要规范治疗!'
		resultData.code = '2'
		resultData.name = '2级高血压'
	} else if (value >= 140 || value2 >= 90) {
		resultData.style = 'color:' + colorStyle[2]
		resultData.color = colorStyle[2]
		resultData.info = '1级高压水平,加强运动可调节血压!'
		resultData.code = '3'
		resultData.name = '1级高血压'
	} else if (value >= 120 || value2 >= 80) {
		resultData.style = 'color:' + colorStyle[3]
		resultData.color = colorStyle[3]
		resultData.info = '血压正常高值水平,要注意控制!'
		resultData.code = '4'
		resultData.name = '正常高值'
	} else if (value >= 90 || value2 >= 60) {
		resultData.style = 'color:' + colorStyle[4]
		resultData.color = colorStyle[4]
		resultData.info = '血压正常,请注意保持!'
		resultData.code = '5'
		resultData.name = '正常血压'
	} else {
		resultData.style = 'color:' + colorStyle[5]
		resultData.color = colorStyle[5]
		resultData.info = '血压偏低，有不适请咨询医生!'
		resultData.code = '6'
		resultData.name = '低血压'
	}
	return resultData
}


// 日常记录 脉搏
export function dynamicMB(value) {
	if (!value) {
		return {}
	}
	const resultData = {}
	if (value >= 120) {
		resultData.style = 'color:' + colorStyle[1]
		resultData.color = colorStyle[1]
		resultData.code = '1'
		resultData.name = '高风险'
	} else if (value >= 100) {
		resultData.style = 'color:' + colorStyle[2]
		resultData.color = colorStyle[2]
		resultData.code = '2'
		resultData.name = '偏高'
	} else if (value >= 60) {
		resultData.style = 'color:' + colorStyle[4]
		resultData.color = colorStyle[4]
		resultData.code = '3'
		resultData.name = '正常'
	} else {
		resultData.style = 'color:' + colorStyle[5]
		resultData.color = colorStyle[5]
		resultData.code = '4'
		resultData.name = '偏低'
	}
	return resultData
}

// 日常记录 血糖判断
export function dynamicBloodGlucose(value, flag) {
	if (!value) {
		return {}
	}
	// flag 1空腹血糖 2早餐后2小时 3午餐前血糖 4午餐后2小时 5晚餐前血糖  6晚餐后2小时 7 睡前或夜间血糖 8 随机血糖 9餐前血糖
	const resultData = {}
	if (flag === '2' || flag === '4' || flag === '6' ||flag === '8') {
		resultData.hint = '<7.8mmol/L为正常范围'
		if (value >= 7.8) {
			resultData.style = 'color:' + colorStyle[2]
			resultData.color = colorStyle[2]
			resultData.info = '血糖高,建议咨询医生!'
			resultData.code = '2'
			resultData.name = '血糖高'
		} else if (value >= 3.9) {
			resultData.style = 'color:' + colorStyle[4]
			resultData.color = colorStyle[4]
			resultData.info = '血糖正常,请继续保持!'
			resultData.code = '3'
			resultData.name = '血糖正常'
		} else if (value >= 0) {
			resultData.style = 'color:' + colorStyle[6]
			resultData.color = colorStyle[6]
			resultData.info = '血糖低,立即进餐并就医!'
			resultData.code = '5'
			resultData.name = '血糖低'
		}
	} else if (flag === '1' || flag === '3' || flag === '5' || flag === '7' || flag === '9') {
		resultData.hint = '3.9~6.1mmol/L为正常范围'
		if (value >= 6.1) {
			resultData.style = 'color:' + colorStyle[2]
			resultData.color = colorStyle[2]
			resultData.info = '血糖高，建议咨询医生!'
			resultData.code = '2'
			resultData.name = '血糖高'
		} else if (value >= 3.9) {
			resultData.style = 'color:' + colorStyle[4]
			resultData.color = colorStyle[4]
			resultData.info = '血糖正常，请继续保持!'
			resultData.code = '3'
			resultData.name = '血糖正常'
		} else if (value >= 0) {
			resultData.style = 'color:' + colorStyle[6]
			resultData.color = colorStyle[6]
			resultData.info = '血糖低，立即进餐并就医!'
			resultData.code = '5'
			resultData.name = '血糖低'
		}
	}
	return resultData
}
// 日常记录 体重BMI判断
export function dynamicBMi(value) {
	if (!value) {
		return {}
	}
	const resultData = {}
	if (value > 28) {
		resultData.style = 'color:' + colorStyle[1]
		resultData.color = colorStyle[1]
		resultData.info = '肥胖,减重对健康有益,建议专业咨询!'
		resultData.code = '1'
		resultData.name = '肥胖'
	} else if (value >= 24) {
		resultData.style = 'color:' + colorStyle[2]
		resultData.color = colorStyle[2]
		resultData.info = '超重,需加以控制,建议专业咨询!'
		resultData.code = '2'
		resultData.name = '超重'
	} else if (value >= 18.5) {
		resultData.style = 'color:' + colorStyle[4]
		resultData.color = colorStyle[4]
		resultData.info = '体重正常,请注意保持!'
		resultData.code = '3'
		resultData.name = '正常'
	} else {
		resultData.style = 'color:' + colorStyle[5]
		resultData.color = colorStyle[5]
		resultData.info = '偏瘦,注意膳食营养!'
		resultData.code = '4'
		resultData.name = '偏瘦'
	}
	return resultData
}
// 日常记录 尿酸判断
export function dynamicUricAcid(value, sexCode) {
	if (!value) {
		return {}
	}
	const resultData = {}
	if (sexCode === '1') {
		resultData.hint = '149~416umol/L为正常范围'
		if (value > 416) {
			resultData.style = 'color:' + colorStyle[2]
			resultData.color = colorStyle[2]
			resultData.info = '尿酸偏高，建议咨询医生!'
			resultData.code = '1'
			resultData.name = '偏高'
		} else if (value >= 149) {
			resultData.style = 'color:' + colorStyle[4]
			resultData.color = colorStyle[4]
			resultData.info = '尿酸正常,请继续保持!'
			resultData.code = '2'
			resultData.name = '正常'
		} else {
			resultData.style = 'color:' + colorStyle[5]
			resultData.color = colorStyle[5]
			resultData.info = '尿酸偏低，建议咨询医生!'
			resultData.code = '3'
			resultData.name = '偏低'
		}
	} else if (sexCode === '2') {
		resultData.hint = '89~357umol/L为正常范围'
		if (value > 357) {
			resultData.style = 'color:' + colorStyle[2]
			resultData.color = colorStyle[2]
			resultData.info = '尿酸偏高，建议咨询医生!'
			resultData.code = '1'
			resultData.name = '偏高'
		} else if (value >= 89) {
			resultData.style = 'color:' + colorStyle[4]
			resultData.color = colorStyle[4]
			resultData.info = '尿酸正常,请继续保持!'
			resultData.code = '2'
			resultData.name = '正常'
		} else {
			resultData.style = 'color:' + colorStyle[5]
			resultData.color = colorStyle[5]
			resultData.info = '尿酸偏低，建议咨询医生!'
			resultData.code = '3'
			resultData.name = '偏低'
		}
	}
	return resultData
}
// 日常记录 尿常规判断
export function dynamicUrinalysis(value, colors, style) {
	// if (!value) {
	// 	return {}
	// }
	// if (style === '1') { // 白细胞
	// } else if (style === '2') { // 亚硝酸盐
	// } else if (style === '3') { // 	尿胆原
	// } else if (style === '4') { // 蛋白质
	// } else if (style === '5') { // 酸碱度
	// } else if (style === '6') { // 潜血
	// } else if (style === '7') { // 比重值
	// } else if (style === '8') { // 胆红素
	// } else if (style === '9') { // 抗坏血酸
	// } else if (style === '10') { // 酮体
	// } else if (style === '11') { // 葡萄糖
	// }
}
// 日常记录 体温判断
export function dynamicHeartRate(value) {
	if (!value) {
		return {}
	}
	const resultData = {}
	if (value > 100) {
		resultData.style = 'color:' + colorStyle[2]
		resultData.color = colorStyle[2]
		resultData.info = '正常心率范围为60-100次/分'
		resultData.code = '1'
		resultData.name = '心动过速'
	} else if (value >= 60) {
		resultData.style = 'color:' + colorStyle[4]
		resultData.color = colorStyle[4]
		resultData.info = '正常心率范围为60-100次/分'
		resultData.code = '2'
		resultData.name = '正常'
	} else {
		resultData.style = 'color:' + colorStyle[5]
		resultData.color = colorStyle[5]
		resultData.info = '正常心率范围为60-100次/分'
		resultData.code = '3'
		resultData.name = '心动过缓'
	}
	return resultData
}

// 日常记录 体温判断
export function dynamicBodyTemperature(value) {
	if (!value) {
		return {}
	}
	const resultData = {}
	if (value > 37) {
		resultData.style = 'color:' + colorStyle[2]
		resultData.color = colorStyle[2]
		resultData.info = '体温偏高，如有不适请咨询医生!'
		resultData.code = '1'
		resultData.name = '偏高'
	} else if (value >= 36) {
		resultData.style = 'color:' + colorStyle[4]
		resultData.color = colorStyle[4]
		resultData.info = '体温正常，请继续保持!'
		resultData.code = '2'
		resultData.name = '正常'
	} else {
		resultData.style = 'color:' + colorStyle[5]
		resultData.color = colorStyle[5]
		resultData.info = '体温偏低，如有不适请咨询医生!'
		resultData.code = '3'
		resultData.name = '偏低'
	}
	return resultData
}
// 日常记录 血氧判断
export function dynamicBloodOxygen(value) {
	if (!value) {
		return {}
	}
	const resultData = {}
	if (value < 94) {
		resultData.style = 'color:' + colorStyle[0]
		resultData.color = colorStyle[0]
		resultData.info = '血氧偏低'
		resultData.code = '0'
		resultData.name = '偏低'
	} else {
		resultData.style = 'color:' + colorStyle[4]
		resultData.color = colorStyle[4]
		resultData.info = '血氧正常'
		resultData.code = '1'
		resultData.name = '正常'
	}
	return resultData
}
// 日常记录 血脂判断
export function dynamicBloodFat(value, flag) {
	if (!value) {
		return {}
	}
	const resultData = {}
	if (flag === '1') { //总胆固醇
		if (value > 5.7) {
			resultData.style = 'color:' + colorStyle[2]
			resultData.color = colorStyle[2]
			resultData.code = '1'
			resultData.name = '偏高'
		} else if (value >= 2.2) {
			resultData.style = 'color:' + colorStyle[4]
			resultData.color = colorStyle[4]
			resultData.code = '2'
			resultData.name = '理想范围'
		} else {
			resultData.style = 'color:' + colorStyle[5]
			resultData.color = colorStyle[5]
			resultData.code = '3'
			resultData.name = '偏低'
		}
	} else if (flag === '2') { //甘油三酯
		if (value > 1.7) {
			resultData.style = 'color:' + colorStyle[2]
			resultData.color = colorStyle[2]
			resultData.code = '1'
			resultData.name = '偏高'
		} else if (value >= 0.2) {
			resultData.style = 'color:' + colorStyle[4]
			resultData.color = colorStyle[4]
			resultData.code = '2'
			resultData.name = '理想范围'
		} else {
			resultData.style = 'color:' + colorStyle[5]
			resultData.color = colorStyle[5]
			resultData.code = '3'
			resultData.name = '偏低'
		}
	} else if (flag === '3') { // 高密度脂蛋白胆固醇
		if (value > 1.7) {
			resultData.style = 'color:' + colorStyle[2]
			resultData.color = colorStyle[2]
			resultData.code = '1'
			resultData.name = '偏高'
		} else if (value >= 0.9) {
			resultData.style = 'color:' + colorStyle[4]
			resultData.color = colorStyle[4]
			resultData.code = '2'
			resultData.name = '理想范围'
		} else {
			resultData.style = 'color:' + colorStyle[5]
			resultData.color = colorStyle[5]
			resultData.code = '3'
			resultData.name = '偏低'
		}
	} else if (flag === '4') { //低密度脂蛋白胆固醇
		if (value > 3.7) {
			resultData.style = 'color:' + colorStyle[2]
			resultData.color = colorStyle[2]
			resultData.code = '1'
			resultData.name = '偏高'
		} else if (value >= 0) {
			resultData.style = 'color:' + colorStyle[4]
			resultData.color = colorStyle[4]
			resultData.code = '2'
			resultData.name = '理想范围'
		} else {
			resultData.style = 'color:' + colorStyle[5]
			resultData.color = colorStyle[5]
			resultData.code = '3'
			resultData.name = '偏低'
		}
	}
	return resultData
}
// 日常记录 腰臀比判断
export function dynamicWhr(value, sex) {
	if (!value) {
		return {}
	}
	const resultData = {}
	if (sex === '2') {
		if (value > 0.85) {
			resultData.style = 'color:' + colorStyle[1]
			resultData.color = colorStyle[1]
			resultData.code = '1'
			resultData.info = '腹型肥胖，建议专业咨询！'
			resultData.name = '腹型肥胖'
		} else {
			resultData.style = 'color:' + colorStyle[4]
			resultData.color = colorStyle[4]
			resultData.code = '1'
			resultData.info = '腰臀比正常，请继续保持！'
			resultData.name = '正常'
		}
	} else {
		if (value > 0.9) {
			resultData.style = 'color:' + colorStyle[1]
			resultData.color = colorStyle[1]
			resultData.code = '1'
			resultData.info = '腹型肥胖，建议专业咨询！'
			resultData.name = '腹型肥胖'
		} else {
			resultData.style = 'color:' + colorStyle[4]
			resultData.color = colorStyle[4]
			resultData.code = '1'
			resultData.info = '腰臀比正常，请继续保持！'
			resultData.name = '正常'
		}
	}
	return resultData
}
// 日常记录 同型半胱氨酸
export function dynamicHomocysteineHcy(value, colors) {
	if (!value) {
		return {}
	}
	if (value >= 15) {
		return 'color:' + colors[0]
	} else if (value >= 5) {
		return 'color:' + colors[1]
	} else {
		return 'color:' + colors[2]
	}
}
//获取对应的icon组列表
export function iconFind(moduleKey, functionKey) {
	const iconStr = uni.getStorageSync('icon')
	const iconList = iconStr ? JSON.parse(iconStr) : []
	const iconData = iconList.filter(item => item.moduleKey === moduleKey && item.functionKey === functionKey)
	if (iconData.length === 0) return ''
	return iconData[0].fileUrl
}
//字典过滤器
export function dictFind(key, dictList) {
	const obj = dictList.filter(item => item.dictValue === key)
	if (obj.length === 0) return ''
	return obj[0].dictLabel
}

//类型过滤
export function dictFindType(key, dictList) {
	const obj = dictList.filter(item => item.value === Number(key))
	if (obj.length === 0) return ''
	return obj[0].label
}

// 图片拼接地址
export function avatarUrlFind(value,type) {
	// 中台
	if (type === '1') {
		return config.remotePicUrlPd+value
	}else if (type === '2') {//小程序
		return config.remotePicUrl+value
	}
	
}